#include <wx/dialup.h>
#include "wxsdialupmanager.h"

namespace {
  wxsRegisterItem<wxsDialUpManager> Reg( _T( "DialUpManager" ), _T( "DialUpManager" ), wxsTTool, _T( "工具" ), 80, false );
  WXS_EV_BEGIN( wxsDialUpManagerEvents )
  WXS_EVI( EVT_DIALUP_CONNECTED, wxEVT_DIALUP_CONNECTED, wxDialUpEvent, Connected )
  WXS_EVI( EVT_DIALUP_DISCONNECTED, wxEVT_DIALUP_DISCONNECTED, wxDialUpEvent, Disconnected )
  WXS_EV_END()
}

wxsDialUpManager::wxsDialUpManager( wxsItemResData* Data ):
  wxsTool(
    Data,
    &Reg.Info,
    wxsDialUpManagerEvents,
    NULL,
    flVariable | flId | flSubclass | flExtraCode ),
  m_iAutoCheckInterval( 60 )
  ,
  m_sWellKnownHost( wxT( "www.yahoo.com" ) ),
  m_iPortNo( 80 ),
  m_sDialCommand( wxT( "/usr/bin/pon" ) ),
  m_sHangUpCommand( wxT( "/usr/bin/poff" ) ) {
}

void wxsDialUpManager::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
    case wxsCPP: {
      AddHeader( _T( "<wx/dialup.h>" ), GetInfo().ClassName, hfInPCH );
      Codef( wxT( "%O = wxDialUpManager::Create();\n" ) );
      if( !m_sWellKnownHost.IsSameAs( wxT( "www.yahoo.com" ) ) || m_iPortNo != 80 ) {
        Codef( _T( "%ASetWellKnownHost(%n, %d);\n" ), m_sWellKnownHost.wx_str(), m_iPortNo );
      }
      if( !m_sDialCommand.IsSameAs( wxT( "/usr/bin/pon" ) ) || !m_sHangUpCommand.IsSameAs( wxT( "/usr/bin/poff" ) ) ) {
        Codef( _T( "%ASetConnectCommand(%n);\n" ), m_sDialCommand.wx_str(), m_sHangUpCommand.wx_str() );
      }
      BuildSetupWindowCode();
      return;
    }
    case wxsUnknownLanguage:
    default: {
      wxsCodeMarks::Unknown( _T( "wxsDialUpManager::OnBuildCreatingCode" ), GetLanguage() );
    }
  }
}

void wxsDialUpManager::OnEnumToolProperties( M_Code_unused long Flags ) {
  bool bAutoCheck;
  if( ( wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS ) > 0 ) {
    bAutoCheck = true;
  } else {
    bAutoCheck = false;
  }
  WXS_BOOL( wxsDialUpManager, m_bAutoCheckOnlineStatus, _T( "Auto-check online status" ), _T( "auto_check_online_status" ), bAutoCheck )
  WXS_LONG( wxsDialUpManager, m_iAutoCheckInterval, _T( "Auto-check interval (secs)" ), wxT( "auto_check_interval" ), 60 )
  WXS_SHORT_STRING( wxsDialUpManager, m_sWellKnownHost, _T( "Well Known Host" ), wxT( "well_known_host" ), wxT( "www.yahoo.com" ), false )
  WXS_LONG( wxsDialUpManager, m_iPortNo, _T( "Port no." ), wxT( "port_no" ), 80 )
  WXS_SHORT_STRING( wxsDialUpManager, m_sDialCommand, _T( "Dial command" ), wxT( "dial_command" ), wxT( "/usr/bin/pon" ), false )
  WXS_SHORT_STRING( wxsDialUpManager, m_sHangUpCommand, _T( "Hang up command" ), wxT( "hangup_command" ), wxT( "/usr/bin/poff" ), false )
}
